//
//  LCZNetWorkTools.m
//  PersonalNews
//
//  Created by dllo on 15/11/28.
//  Copyright © 2015年 changshuhua. All rights reserved.
//

#import "LCZNetWorkTools.h"

@implementation LCZNetWorkTools
+ (void)getdataWithString:(NSString *)string block:(AFNData)block
{
    
    
    AFNetworkReachabilityManager *netWorkManager = [AFNetworkReachabilityManager sharedManager];
    NSString *url_string = [NSString stringWithFormat:@"%@",string];
    
    AFHTTPSessionManager* manager = [AFHTTPSessionManager manager];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain", @"text/json", @"application/json", @"text/javascript", @"text/html",  nil];
    [manager GET:url_string parameters:nil success:^(NSURLSessionTask *task, id responseObject) {
        [netWorkManager stopMonitoring];
        block(responseObject);
        //        NSLog(@"JSON: %@", responseObject);
    } failure:^(NSURLSessionTask *operation, NSError *error) {
        NSLog(@"Error: %@", error);
        //BLOCK (operation);
    }];
}

+ (void)showNetWorkStatus:(netWorkStatus)result
{
    AFNetworkReachabilityManager *manager =  [AFNetworkReachabilityManager sharedManager];
    [manager startMonitoring];
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        
        NSString *str;
        switch (status) {
            case AFNetworkReachabilityStatusUnknown:
                str = @"未知网络";
                //                [self.hud removeFromSuperview];
                break;
            case AFNetworkReachabilityStatusNotReachable:
                str = @"网络未连接";
                
                //                [self.hud removeFromSuperview];
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
                str = @"网络已连接";
                //                [self createData];
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi:
                str = @"WiFi已连接";
                //                [self createData];
                break;
            default:
                break;
        }
        result(str);
    }];
    
}

@end
